<template>
  <div class="app-container">
    <el-form :model="queryParams" :ref="queryFormRef" inline v-show="showSearch" label-width="100px" @keyup.enter.native="handleQuery">
      <el-form-item label="定时任务" prop="scheduleJobId">
        <lam-dict-select v-model="queryParams.scheduleJobId" dictCode="scheduleJob" dictType="tableDict" clearable />
      </el-form-item>
      <el-form-item label="任务分组" prop="jobGroup">
        <lam-dict-select v-model="queryParams.jobGroup" dictCode="job_group" clearable placeholder="" style="width: 100%;" />
      </el-form-item>
      <el-form-item label="执行类" prop="exeClass">
        <el-input v-model="queryParams.exeClass" placeholder="请输入执行类" clearable/>
      </el-form-item>
      <el-form-item label="触发方式" prop="triggerType">
        <lam-dict-select v-model="queryParams.triggerType" dictCode="trigger_type" placeholder="触发方式" clearable />
      </el-form-item>
      <el-form-item label="操作人" prop="createBy">
        <el-input v-model="queryParams.createBy" placeholder="" clearable/>
      </el-form-item>
      <el-form-item label="开始执行时间" prop="exeStartTimeBegin">
        <el-date-picker clearable v-model="queryParams.exeStartTimeBegin" value-format="yyyy-MM-dd" type="date" style="width: 93%;">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="解释时间" prop="exeStartTimeEnd">
        <el-date-picker clearable v-model="queryParams.exeStartTimeEnd" value-format="yyyy-MM-dd" type="date" style="width: 93%;">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="执行耗时" prop="exeCostBegin">
        <el-input v-model="queryParams.exeCostBegin" placeholder="开始" clearable style="width:90px;"/>
        -
      </el-form-item>
      <el-form-item prop="exeCostEnd">
        <el-input v-model="queryParams.exeCostEnd" placeholder="结束" clearable style="width:91px;"/>
      </el-form-item>
      <el-form-item label="执行结果" prop="exeStatus">
        <lam-dict-select v-model="queryParams.exeStatus" dictCode="exe_status_type" placeholder="请选择执行结果" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search"  @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="tool-bar-btn">
        <el-button type="success" icon="el-icon-tickets"  :disabled="single" @click="handleDetail">详情</el-button>
        <el-button type="danger" icon="el-icon-delete"  :disabled="multiple" @click="handleDelete" v-hasPerms="['sched:jobLog:remove']">删除</el-button>
        <el-button type="warning" icon="el-icon-download"  @click="handleExport" v-hasPerms="['sched:jobLog:export']">导出</el-button>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </div>

    <selected-info :count="selectedRows.length" :onClearSelected="onClearSelected" />
    <el-table :ref="dataTableRef" v-loading="loading" :data="dataList" stripe border @selection-change="onSelectChange"
          :default-sort = "defaultSort" @sort-change="onSortChange" :row-key="rowKey" >
      <el-table-column type="selection" width="55" align="center" fixed="left"/>
      <el-table-column label="序号" align="center" prop="id" sortable="custom" width="80" />
      <el-table-column label="任务编号" align="center" prop="scheduleJobId" sortable="custom"  width="100"/>
      <el-table-column label="任务名称" align="center" prop="jobName" width="180"/>
      <el-table-column label="任务分组" align="center" prop="jobGroup" width="120"/>
      <el-table-column label="触发方式" align="center" prop="triggerTypeDictText" width="120"/>
      <el-table-column label="开始执行时间" align="center" prop="exeStartTime" width="180" sortable="custom"/>
      <el-table-column label="执行结束时间" align="center" prop="exeEndTime" width="180"/>
      <el-table-column label="操作人" align="center" prop="createBy" width="100"/>
      <el-table-column label="执行耗时" align="center" prop="exeCostText" width="180"/>
      <el-table-column label="执行结果" align="center" prop="exeStatusDictText" width="120">
        <template slot-scope="{row}">
          <JobLogStatus :value="row.exeStatus" :text="row.exeStatusDictText" />
        </template>
      </el-table-column>
      <el-table-column label="执行结果信息" align="center" prop="exeMsg" width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="实例IP" align="center" prop="instanceIp" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="实例ID" align="center" prop="instanceId" width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="调度器" align="center" prop="schedName" width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="执行时任务状态" align="center" prop="statusDictText" width="120">
        <template slot-scope="{row}">
          <JobStatus :value="row.status" :text="row.statusDictText"/>
        </template>
      </el-table-column>
      <el-table-column label="con表达式" align="center" prop="cronExpression" width="150"/>
      <el-table-column label="表达式描述" align="center" prop="cronExpDesc" width="180"/>
      <el-table-column label="执行类" align="center" prop="exeClass" width="300" :show-overflow-tooltip="true"/>
      <el-table-column label="执行方法" align="center" prop="exeMethod" width="120"/>
      <el-table-column label="执行参数" align="center" prop="exeParam" width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="并发类型" align="center" prop="concurrentTypeDictText" width="120"/>
      <el-table-column label="执行错误策略" align="center" prop="misfirePolicyDictText" width="120"/>
      <el-table-column label="备注信息" align="center" prop="remark" width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="140">
        <template slot-scope="{row}">
          <el-button type="text" icon="el-icon-tickets" @click="handleDetail(row)" >详情</el-button>
          <el-button type="text" icon="el-icon-delete" @click="handleDelete(row)" v-hasPerms="['sched:jobLog:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="!loading" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"  @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <EditScheduleJobLog ref="formDialog" @ok="getList" />
	<!-- 导出对话框 -->
	<ToExport ref="exportDialog" />

  </div>
</template>
<style scoped>
</style>
<script>
import {httpGet, httpDel} from '@/api';
import { IndexListMixin } from '@/components/mixins/IndexListMixin';
import ToExport from '@/components/download/ToExport';
import EditScheduleJobLog from './edit';
import JobStatus from '../job/JobStatus';
import JobLogStatus from './JobLogStatus';

export default {
  name: "ScheduleJobLog",
  mixins:[IndexListMixin],
  components: {
	  ToExport,
    EditScheduleJobLog,
    JobLogStatus,
    JobStatus
  },
  data() {
    return {
      // 查询参数
      queryParams: {
        scheduleJobId: null,
        jobName: null,
        jobGroup: null,
        exeClass: null,
        exeStartTimeBegin: null,
        exeStartTimeEnd: null,
        exeCostBegin: null,
        exeCostEnd: null,
        exeStatus: null,
        pageNum: 1,
        pageSize: 10
      },
      url: {
      	exportXls: '/sched/jobLog/export',
        base: '/sched/jobLog/',
      	list: '/sched/jobLog/list',
      	// jobList: '/sched/job/simpleList',
      }
    };
  },
  created() {
    if(this.$route.params && this.$route.params.jobId){
      this.queryParams.scheduleJobId = this.$route.params.jobId;
    }
    this.getList();
  },
  mounted(){
  },
  methods: {
    getList() {
      this.loadData(this.url.list);
    },

    /** 查看详情按钮操作 */
    handleDetail(row) {
      const id = row.id || this.selectedRowKeys
      this.$refs.formDialog.toDetail("定时调度日志", httpGet(this.url.base + id));
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      this.deleteData(this.url.base, row.id);
    },

    /** 导出按钮操作 */
    handleExport() {
      this.exportData('调度日志', this.url.exportXls, this.queryParams);
    }

  }
};
</script>
